﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HKEA.CMS.Core;
using HKEA.CMS.Core.BLL;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.BLL.Mtbl;

namespace WebApplication.test
{
    public partial class AjaxText_Nicky : System.Web.UI.Page
    {
        public int mark_a = 0,mark_b=0;
        mtblProductCat ent = new mtblProductCat();
        mtblProductCatBLL bll = mtblProductCatBLL.GetInstance();
        List<mtblProductCat> mtblProductCatList = new List<mtblProductCat>();
        protected void Page_Load(object sender, EventArgs e)
        {
            RepeateBound();
        }
        protected void RepeateBound()
        {
            mtblProductCatList = bll.GetListByENT(ent);
            List<mtblProductCat> obj_A = mtblProductCatList.Where(p => p.ProductCatID.Contains("A")).ToList();
            List<mtblProductCat> obj_B = mtblProductCatList.Where(p => p.ProductCatID.Contains("B")).ToList();
            List<mtblProductCat> obj_C = mtblProductCatList.Where(p => p.ProductCatID.Contains("C")).ToList();
            List<mtblProductCat> obj_D = mtblProductCatList.Where(p => p.ProductCatID.Contains("D")).ToList();
            List<mtblProductCat> obj_E = mtblProductCatList.Where(p => p.ProductCatID.Contains("E")).ToList();
            //var newList = new List<List<mtblProductCat>> { obj_A, obj_B, obj_C, obj_D, obj_E };

            IList<List<mtblProductCat>> newList = new List<List<mtblProductCat>>();
            newList.Add(obj_A);
            newList.Add(obj_B);
            newList.Add(obj_C);
            newList.Add(obj_D);
            newList.Add(obj_E);


            ProductCategory.DataSource = newList;
            ProductCategory.DataBind();
        }

        protected void ProductCategory_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            //List<mtblProductCat> list = e.Item.DataItem ;
            List<mtblProductCat> list = new List<mtblProductCat>();
            foreach (var item in e.Item.DataItem as List<mtblProductCat>)
            {
                mtblProductCat ent = new mtblProductCat();
                ent.ProductCatUID = item.ProductCatUID;
                ent.ProductCatID = item.ProductCatID;
                ent.ProductCat_Chi = item.ProductCat_Chi;
                ent.ProductCat_Eng = item.ProductCat_Eng;
                list.Add(ent);
            }

            Repeater CategoryList = e.Item.FindControl("CategoryList") as Repeater;
            if (list != null)
            {
                CategoryList.DataSource = list;
                CategoryList.DataBind();
            }
        }
    }
}